﻿using MoetutuServer.Helper;
using MoetutuServer.WebSite.Pixiv;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using static MoetutuServer.Pixiv.ProcessImg.Helper;

namespace MoetutuServer.Pixiv.ProcessImg
{
    public partial class ProcessControl : UserControl
    {
        public ProcessControl()
        {
            InitializeComponent();
            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
        }
        Queue<ArtInfo> UserIdLIST = new Queue<ArtInfo>();

        private void button3_Click(object sender, EventArgs e)
        {
       

        }
 

        private void button1_Click(object sender, EventArgs e)
        {
            FileHelper.FloderExits(StaticValue.ProcessImgPath1, true);
            System.Diagnostics.Process.Start(StaticValue.ProcessImgPath1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Console.WriteLine(FileHelper.GetFullFileNameList(StaticValue.ProcessImgPath1).Count);
            foreach (String line in FileHelper.GetFullFileNameList(StaticValue.ProcessImgPath1))
            {
                Console.WriteLine(line);
                UserIdLIST.Enqueue(Helper.GetUserId(line));
                FileHelper.FileMove(line, StaticValue.ProcessImgPath1 + "OldImg\\" + Path.GetFileName(line));

            }
            Console.WriteLine("分析完毕！");
           
        }

        private void button4_Click(object sender, EventArgs e)
        {
           

        }

    

        private void button5_Click(object sender, EventArgs e)
        {
            FileHelper.AppendUTF8Text(StaticValue.SafeTagPath, textBox1.Text);

            textBox1.Text = "";
        }

   



        private void button7_Click(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            AddTag();
        }

        private void AddTag()
        {
            if (textBox1.Text != "" && textBox2.Text != "")
            {
                TagHelper.XmlAdd(StaticValue.XmlPath, textBox1.Text.Trim(), textBox2.Text.Trim());
                textBox1.Text = "";
                textBox2.Text = "";
            }
            else
            {

                MessageBox.Show("汉化标签不能为空");
            }
        }

        private void button3_Click_1(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            List<string> TempList = FileHelper.ReadAllLine(MoetutuServer.Helper.Currency.SelectFile.FileSelect());
            listBox1.Items.AddRange(TempList.ToArray());

        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Console.WriteLine(listBox1.SelectedIndex);
        
            StartHelper(TextHelper.ReplaceText(listBox1.SelectedItem.ToString(), "   图片数量：[0-9]{0,}",""));
        }

        private void StartHelper(string TagText)
        {
            textBox1.Text = TagText;
            if (checkBox2.Checked) {
                string Url = "";
                switch (comboBox2.Text) {
                    case "P站":
                        Url = "https://www.pixiv.net/search.php?s_mode=s_tag&word=" + TagText;
                        break;
                    case "GOOGLE":
                        Url = "https://www.google.com.hk/search?q=" + TagText;
                        break;
                   
                    case "百度翻译":
                        Url = "http://fanyi.baidu.com/#jp/zh/" + TagText;
                        break;
                    default:
                        Url = "https://www.baidu.com/s?wd=" + TagText;
                        break;
                }
                FloderHelper.OpenFloder(Url);
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            List<string> TempList = FileHelper.ReadAllLine(MoetutuServer.Helper.Currency.SelectFile.FileSelect());
            listBox1.Items.AddRange(TagListShort(TempList).ToArray());
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar==13)
                AddTag();
        }
    }
}
